//http_build_query — 生成 URL-encode 之后的请求字符串
//Example #1 http_build_query() 使用示例
<?php
$data = array('foo'=>'bar',
              'baz'=>'boom',
              'cow'=>'milk',
              'php'=>'hypertext processor');

echo http_build_query($data) . "\n";
echo http_build_query($data, '', '&amp;');
?>
//以上例程会输出：
//foo=bar&baz=boom&cow=milk&php=hypertext+processor
//foo=bar&amp;baz=boom&amp;cow=milk&amp;php=hypertext+processor

//Example #2 http_build_query() 使用数字下标的元素
<?php
$data = array('foo', 'bar', 'baz', 'boom', 'cow' => 'milk', 'php' =>'hypertext processor');
echo http_build_query($data) . "\n";
echo http_build_query($data, 'myvar_');
?>
//以上例程会输出：
//0=foo&1=bar&2=baz&3=boom&cow=milk&php=hypertext+processor
//myvar_0=foo&myvar_1=bar&myvar_2=baz&myvar_3=boom&cow=milk&php=hypertext+processor

//Example #3 http_build_query() 使用复杂的数组
<?php
$data = array('user'=>array('name'=>'Bob Smith',
                            'age'=>47,
                            'sex'=>'M',
                            'dob'=>'5/12/1956'),
              'pastimes'=>array('golf', 'opera', 'poker', 'rap'),
              'children'=>array('bobby'=>array('age'=>12,
                                               'sex'=>'M'),
                                'sally'=>array('age'=>8,
                                               'sex'=>'F')),
              'CEO');
echo http_build_query($data, 'flags_');
?>
//这会输出：（为了可读性，字已经换行了）
//user%5Bname%5D=Bob+Smith&user%5Bage%5D=47&user%5Bsex%5D=M&
//user%5Bdob%5D=5%2F12%2F1956&pastimes%5B0%5D=golf&pastimes%5B1%5D=opera&
//pastimes%5B2%5D=poker&pastimes%5B3%5D=rap&children%5Bbobby%5D%5Bage%5D=12&
//children%5Bbobby%5D%5Bsex%5D=M&children%5Bsally%5D%5Bage%5D=8&
//children%5Bsally%5D%5Bsex%5D=F&flags_0=CEO
//Note:
//只有基础数组中的数字下标元素“CEO”才获取了前缀，其它数字下标元素（如 pastimes 下的元素）则不需要为了合法的变量名而加上前缀。

//Example #4 http_build_query() 使用对象
<?php
class parentClass {
    public    $pub      = 'publicParent';
    protected $prot     = 'protectedParent';
    private   $priv     = 'privateParent';
    public    $pub_bar  = Null;
    protected $prot_bar = Null;
    private   $priv_bar = Null;

    public function __construct(){
        $this->pub_bar  = new childClass();
        $this->prot_bar = new childClass();
        $this->priv_bar = new childClass();
    }
}
class childClass {
    public    $pub  = 'publicChild';
    protected $prot = 'protectedChild';
    private   $priv = 'privateChild';
}
$parent = new parentClass();
echo http_build_query($parent);
?>
//以上例程会输出：
//pub=publicParent&pub_bar%5Bpub%5D=publicChild